how to add a domain user as a local administrator ( add to local admin group) using a vbs script 您所在的位置:网站首页 user/administrator how to add a domain user as a local administrator ( add to local admin group) using a vbs script

how to add a domain user as a local administrator ( add to local admin group) using a vbs script

2023-04-21 16:14| 来源: 网络整理| 查看: 265

Hi I tried several combinations just need to prompt user to enter the domain user account that need to be added as a local administrator on the current PC and let them type the username and need to hardcode the domain admin account in the vbs script can we do this. I tried this but it did not work for me

Option Explicit Dim domainAdmin, domainAdminPassword, domainUserName, group, groupMember Dim objNetwork, objGroup, objUser ' Prompt user for domain user name domainUserName = InputBox("Enter the domain user name to add to the local Administrators group:", "Add User to Local Administrators Group") ' Hard-code domain admin credentials domainAdmin = "" domainAdminPassword = "" ' Get a reference to the local Administrators group Set objGroup = GetObject("WinNT://./Administrators") ' Get a reference to the user to add to the group Set objUser = GetObject("WinNT://" & domainUserName) ' Add the user to the local Administrators group On Error Resume Next objGroup.Add(objUser.ADsPath) If Err.Number = 0 Then ' Display success message MsgBox "User " & domainUserName & " has been added to the local Administrators group.", vbInformation, "User Added" Else ' Display error message MsgBox "Failed to add user " & domainUserName & " to the local Administrators group. Error: " & Err.Description, vbCritical, "Error Adding User" End If ' Clean up Set objUser = Nothing Set objGroup = Nothing


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有